package com.hdd.art.biz.painting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.painting.entity.PaintingMedia;
import com.hdd.art.biz.painting.mapper.PaintingMediaMapper;
import com.hdd.art.biz.painting.service.PaintingMediaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-06-28
 */
@Service
public class PaintingMediaServiceImpl extends ServiceImpl<PaintingMediaMapper, PaintingMedia> implements PaintingMediaService {

    @Override
    public void addVoice(PaintingMedia paintingMedia) {
        baseMapper.insert(paintingMedia);
    }

    @Override
    public List<PaintingMedia> mediaList(String workId) {
        QueryWrapper<PaintingMedia> wrapper = new QueryWrapper<>();
        wrapper.eq("works_id",workId);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public void delPaintingMedia(Integer id) {
        baseMapper.deleteById(id);
    }


    @Override
    public void mediaUse(String workId, Integer id) {
        QueryWrapper<PaintingMedia> wrapper = new QueryWrapper<>();
        wrapper.eq("works_id",workId);
        PaintingMedia paintingMedia = new PaintingMedia();
        paintingMedia.setIsUse("F");
        baseMapper.update(paintingMedia,wrapper);
        wrapper.eq("id",id);
        paintingMedia.setIsUse("T");
        baseMapper.update(paintingMedia,wrapper);
    }


    @Override
    public PaintingMedia findUseMedia(String workId) {
        QueryWrapper<PaintingMedia> wrapper = new QueryWrapper<>();
        wrapper.eq("works_id",workId);
        return baseMapper.selectOne(wrapper);
    }

}
